package com.itheima.work;

import java.util.HashMap;
import java.util.Map;

/**
 * @auther Macrydy
 * @date 2020/7/1 18:06
 *
 *   有以下字符串：
 *
 * ​              String str = “woaiheimawoaijavawoaichaunzhi”;
 *
 * ​       请编程统计每个字符出现的次数
 */
public class Test2 {
    public static void main(String[] args) {
        String str = "woaiheimawoaijavawoaichaunzhi";

        Map<Character,Integer> map=new HashMap<>();

        for (int i = 0; i <str.length() ; i++) {
            char c = str.charAt(i);
            if (!map.containsKey(c)){
                map.put(c, 1);
            }else {
                Integer num = map.get(c);
                num++;
                map.put(c, num);
            }
        }

        map.forEach((c, num) -> System.out.print(c+"("+num+")"));
    }
}
